package com.analytical.www.pop

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.analytical.www.R
import com.analytical.www.adapter.AdapterSampleInput
import com.analytical.www.bean.BeanSample
import com.analytical.www.component.SoundPoolManager
import com.analytical.www.databinding.PopTestResultBinding
import com.analytical.www.util.UtilFastClickAbort

/**
 * @author shawn
 * @since 2023/5/18
 */
class PopTestResult(context: Context) : PopBase(context), AdapterSampleInput.ItemClickListener {
    private var binding:PopTestResultBinding
    var listener:IActionListener? = null
    private  var mData:MutableList<BeanSample> = mutableListOf()
    private var selectItem:BeanSample? = null
    private lateinit var mAdapter:AdapterSampleInput
    init {
        setBackgroundDrawable(null)
        initRecycleData()
        val view = LayoutInflater.from(context).inflate(R.layout.pop_test_result, null)
        contentView = view
        binding = PopTestResultBinding.bind(view)
        mAdapter = AdapterSampleInput(context,this)
        mAdapter.mData = mData
        binding.rlSample.apply {
            layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL,false)
            adapter = mAdapter
        }
//        mAdapter.notifyDataSetChanged()
        binding.ll1.setOnClickListener {
            if(UtilFastClickAbort.isFastClick()){
                return@setOnClickListener
            }
            SoundPoolManager.showSound(R.raw.tap_button)
            listener?.onActionOk("input")
            dismiss()
        }
        binding.ll4.setOnClickListener {
            if(UtilFastClickAbort.isFastClick()){
                return@setOnClickListener
            }
            SoundPoolManager.showSound(R.raw.tap_button)
            listener?.onActionNo()
            dismiss()
        }
    }

    private fun initRecycleData() {
        mData.add(BeanSample("测试结果 2022/2/3"))
        mData.add(BeanSample("测试结果 2022/5/3"))
        mData.add(BeanSample("正五十烷 测试日志"))
        mData.add(BeanSample("测试结果 2022/7/22"))
        mData.add(BeanSample("测试结果 2022/8/11"))
        mData.add(BeanSample("测试结果 2022/2/3"))
        mData.add(BeanSample("汽油 测试日志"))
        mData.add(BeanSample("甲醇汽油 测试日志"))
        mData.add(BeanSample("汽油 202312a 测试日志"))
        mData.add(BeanSample("正十六烷 测试日志"))
    }

    interface IActionListener {
        fun onActionOk(input:String)
        fun onActionNo()
    }

    override fun click(position: Int) {

    }

    fun show(parent:View){
        showAtLocation(parent,Gravity.NO_GRAVITY,0,0)
    }
}